package cn.hsa.xxx.salesReport.bo.Impl;



import cn.hsa.xxx.salesReport.bo.BookSalesMonitorBO;
import cn.hsa.xxx.salesReport.dao.BookSalesMonitorDAO;
import cn.hsa.xxx.api.dto.BookSalesMonitorDTO;
import cn.hsa.xxx.salesReport.dto.BookSalesMonitorDTOConverter;
import cn.hsa.xxx.salesReport.entity.BookSalesMonitorDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
public class BookSalesMonitorBOImpl implements BookSalesMonitorBO {

    @Resource
    BookSalesMonitorDAO bookSalesMonitorDAO;

    @Autowired
    BookSalesMonitorDTOConverter bookSalesMonitorDTOConverter;

    @Override
    public BookSalesMonitorDTO add(BookSalesMonitorDTO bookSalesMonitorDTO) {
        BookSalesMonitorDO bookSalesMonitorDO = bookSalesMonitorDTOConverter.convertToBookSalesMonitorDO(bookSalesMonitorDTO);
        bookSalesMonitorDAO.insert(bookSalesMonitorDO);
        return bookSalesMonitorDTOConverter.convertToBookSalesMonitorDTO(bookSalesMonitorDO);
    }

    @Override
    public String delete(String id) {
        bookSalesMonitorDAO.deleteById(id);
        return "删除成功";
    }

    @Override
    public BookSalesMonitorDTO get(String id) {
        BookSalesMonitorDO bookSalesMonitorDO = bookSalesMonitorDAO.selectById(id);
        BookSalesMonitorDTO bookSalesMonitorDTO = bookSalesMonitorDTOConverter.convertToBookSalesMonitorDTO(bookSalesMonitorDO);
        return bookSalesMonitorDTO;
    }

    @Override
    public String update(BookSalesMonitorDTO bookSalesMonitorDTO) {
        BookSalesMonitorDO bookSalesMonitorDO = bookSalesMonitorDTOConverter.convertToBookSalesMonitorDO(bookSalesMonitorDTO);
        bookSalesMonitorDAO.updateById(bookSalesMonitorDO);
        return "更新成功";
    }

    @Override
    public List<BookSalesMonitorDTO> getAll() {
        List<BookSalesMonitorDO> bookSalesMonitorDOList = bookSalesMonitorDAO.selectList(null);
        List<BookSalesMonitorDTO> bookSalesMonitorDTOList = new ArrayList<>();
        for (BookSalesMonitorDO bookSalesMonitorDO : bookSalesMonitorDOList) {
            bookSalesMonitorDTOList.add(bookSalesMonitorDTOConverter.convertToBookSalesMonitorDTO(bookSalesMonitorDO));
        }
        return bookSalesMonitorDTOList;
    }

    @Override
    public List<BookSalesMonitorDTO> getByTime(Date beginDate, Date endDate) {
        List<BookSalesMonitorDO> bookSalesMonitorDOList = bookSalesMonitorDAO.findByTime(beginDate, endDate);
        List<BookSalesMonitorDTO> bookSalesMonitorDTOList = new ArrayList<>();
        for (BookSalesMonitorDO bookSalesMonitorDO : bookSalesMonitorDOList) {
            bookSalesMonitorDTOList.add(bookSalesMonitorDTOConverter.convertToBookSalesMonitorDTO(bookSalesMonitorDO));
        }
        return bookSalesMonitorDTOList;
    }
}
